package net.message
{

	import flash.utils.IDataInput;
	import flash.utils.IDataOutput;

	import net.handler.IMessageHandler;

	import util.GameByteArray;

	public class BaseMessage
	{
		public var body:GameByteArray;
		public var type:uint;
		public var handler:IMessageHandler;

		public function BaseMessage()
		{
			body = new GameByteArray();
		}

		protected function readString(data:IDataInput):String
		{
			var length:uint = data.readInt();
			return data.readUTFBytes(length);
		}

		protected function readLong(data:IDataInput):String
		{
			var long:String = "";

			for(var i:int = 0; i < 8; i++)
			{
				long += data.readByte().toString(16);
			}
			return long;
		}

		public function readMessage(data:IDataInput):void
		{

		}

		public function writeMessage(... agrs):void
		{

		}

		public function handlerMessage():void
		{
			if(handler != null)
			{
				handler.execute(this);
			}
		}
	}
}